#include "threadCtrl.h"

ThreadCtrl &ThreadCtrl::getInstance()
{
    static ThreadCtrl instance;
    return instance;
}

ThreadCtrl::ThreadCtrl()
{
    this->threadInit();
    this->semInit();
    this->mailInit();
    this->QueueInit();
    this->threadStart();
}

ThreadCtrl::~ThreadCtrl()
{
}

void ThreadCtrl::threadInit()
{
    this->armKey = make_unique<ArmKey>(2048, 20, 20, "ArmKey");
    this->printTest = make_unique<PrintTest>(2048, 20, 20, "PrintTest");
    this->led = make_unique<LED>(2048, 20, 20, "LedThread");
}

void ThreadCtrl::threadStart()
{
    this->armKey->start();
    // this->printTest->start();
    this->led->start();
}

void ThreadCtrl::semInit()
{
    this->buttonSem = make_shared<Semaphore>("ButtonSem", 0);
    this->armKey->setButtonSem(this->buttonSem);
    this->printTest->setButtonSem(this->buttonSem);

    this->ledSem = make_shared<Semaphore>("LedSem", 0);
    this->led->setLedSem(this->ledSem);
    this->armKey->setLedSem(this->ledSem);
}

void ThreadCtrl::mailInit()
{
    this->buttonMail = make_shared<Mail<std::string, 10>>("ButtonMail");
    this->armKey->setButtonMail(this->buttonMail);
    this->printTest->setButtonMail(this->buttonMail);
}

void ThreadCtrl::QueueInit()
{
    this->buttonQueue = make_shared<Queue<int, 10>>("ButtonQueue");
    this->armKey->setButtonQueue(this->buttonQueue);
    this->printTest->setButtonQueue(this->buttonQueue);
}
